#include "Data.h"

shuju::shuju(){

}


void shuju::setData(const QString &qs,int n,int value){
    stringstream ss(qs.toStdString());
    for(int i=0;i<n;i++){
        for(int j=0;j<value+n;j++){
            ss >> v[i][j];
        }
    }
}
QString shuju::getAns(int n,int value){
    try{
        if(value == 1){
            solve::solve_guass(v,gvans,n);
            QString tmp;
            QString ret;
            for(int i=0;i<n;i++){
               // ss << gvans[i] << "";
                tmp = QString::number(gvans[i]);
                ret = ret + tmp;
                ret = ret + QString("\n");
            }
            return ret;
        }else{
            solve::solve_doolittle(v,vans,n);
            QString tmp;
            QString ret;
            for(int i=0;i<n;i++){
                for(int j=0;j<=i;j++){
                    tmp = QString::number(vans[i][j]);
                    ret = ret + tmp;
                    ret = ret + QString("    ");
                }
                ret = ret + QString("\n");
            }
            return ret;
        }
    }catch(...){
        return QString("Error!");
    }
}

QString shuju::solveProblem(const QString &qs,int n,int value){
    setData(qs,n,value);
    return getAns(n,value);
}
